<?php
namespace app\admin\hook\Meta;
use support\exception\ValidateException;
use think\facade\Db;
use support\Log;
use app\admin\model\Meta\Web as WebModel;

class Web{



	/**
	 *@description 添加前置钩子
	 *@buildcode(false)
	*/
	function beforAdd(&$data){
		$character = create_character($data);
		Log::info("添加角色:".$character);
		$response_data = json_decode($character, true);
		if(isset($response_data["data"]))
		{
			$data["role_id"] = $response_data["data"]["characterId"];
		}
	}


	/**
	 *@description 删除前置钩子
	 *@buildcode(false)
	*/
	function beforDelete($idx){
		$rows = WebModel::where('web_id', $idx)->select()->toArray();
		foreach($rows as $row)
		{
			if($row["role_id"])
			{
				$response = delete_character($row["role_id"]);
				Log::info("删除角色:".$response);
			}
		}
	}


	/**
	 *@description 角色更新前置钩子
	 *@buildcode(false)
	*/
	function beforUpdate_character($idx)
	{
		$rows = WebModel::where('web_id', $idx)->select()->toArray();
		foreach($rows as $row)
		{
			if($row["role_id"])
			{
				$response =  update_character($row);
				Log::info("角色更新:".$response);
			}
		}
	}


}